# 创建字典的方式：直接一个个写出来，dict()，先创建一个空的然后再一个个添加kv
inventory = {  
    "978-1234567890": {"title": "Python编程从入门到实践", "author": "埃里克·马瑟斯", "stock": 50, "price": 39.99},  
    "978-2345678901": {"title": "算法导论", "author": "托马斯·科尔曼", "stock": 20, "price": 59.99},  
    "978-3456789012": {"title": "代码大全", "author": "史蒂夫·迈克康奈尔", "stock": 35, "price": 49.99}  
}
# 字典取值
print(inventory["978-1234567890"])
print(inventory.get("978-12345", {}))  # 找不到不报错，不会退出程序，可以给默认值


inventory["978-1234567890"]["stock"]+=10

for key in inventory:
    print(inventory[key]["price"])

if "978-0987654321" in inventory:
    print(inventory["978-0987654321"].get("stock"))
    

else:
    print("书籍未找到")

print(inventory.get("978-0987654321", "书籍未找到"))

inventory.pop("978-3456789012")
print(inventory)